package kr.nexmore.slmsample2.handler;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

public class ExitHandler {
	@Execute
	public void execute(EPartService partService, IWorkbench workbench,
			Shell shell) {
		if (!partService.getDirtyParts().isEmpty()) {
			boolean confirm = MessageDialog.openConfirm(shell, "Unsaved",
					"Unsaved data, do you want to save?");
			if (confirm) {
				partService.saveAll(false); // we close the workbench here to
											// avoid // the second popup
											// workbench.close(); // the
											// Workbench continues to run, until
											// we leave this handler // so we
											// return; return; } } boolean
											// result =
											// MessageDialog.openConfirm( shell,
											// "Close", "Close application?");
											// if (result) { workbench.close();
											// } }
			}
		}
	}
}
